package org.six11.olive3.client;

import org.six11.olive3.net.Message;
import org.six11.olive3.net.MessageHandler;
import org.six11.olive3.net.MessageNames;
import org.six11.olive3.net.Message.Statement;
import org.six11.olive3.util.MiscFunctions;
import org.six11.util2.Debug;
import org.six11.util2.pen.Pt;

/**
 * 
 * 
 * @author Gabe Johnson <johnsogg@cmu.edu>
 * 
 */
public class ForeignPenHandler extends MessageHandler {

  private OliveState state;

  public ForeignPenHandler(OliveState state) {
    this.state = state;
  }

  public void handleLater(Message m) {
    String otherUser = m.getParamValue(MessageNames.PARAM_USER_ID);
    for (Statement s : m.statements) {
      if (s.type.equals("pt")) {
        Pt pt = new Pt(MiscFunctions.safeInt(s.required.get(0).text), MiscFunctions
            .safeInt(s.required.get(1).text));
        state.addForeignSequenceProgress(otherUser, pt);
      } else if (s.type.equals("up")) {
        state.addForeignSequenceEnd(otherUser);
      }
    }
  }

}
